package com.lc.afbx.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiCarCc;
import com.lc.afbx.conn.GetApiShowVehicle;
import com.lc.afbx.conn.InsureanceDutyfeeGet;
import com.lc.afbx.conn.PostIDCard;
import com.lc.afbx.conn.PostVehicleCard;
import com.lc.afbx.dialog.PictureDialog;
import com.lc.afbx.dialog.ShowPicDialog;
import com.lc.afbx.util.Base64Encoder;
import com.lc.afbx.util.DateTimePickDialogUtil;
import com.lc.afbx.util.MEditTextListener;
import com.lc.afbx.util.MyToast;
import com.lc.afbx.util.PictureUtil;
import com.lc.afbx.util.PrefrenceConfig;
import com.lc.afbx.util.Validator;
import com.zcx.helper.activity.AppPictureV4Activity;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilBase64;
import com.zcx.helper.util.UtilLog;
import com.zcx.helper.util.UtilMD5;
import com.zcx.helper.util.UtilToast;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2016/5/23.
 */
public class CompulsoryInsuranceFillInfoActivity extends BasePictureActivity implements View.OnClickListener {

    private Button btnXiaYiBu;
    private HashMap<Integer, String> declareMap;
    private int i;
    private EditText carType;
    private EditText useNature;

//    private List<String> natureList;
//    private List<String> vehicletypeList;
//    private GetApiShowVehicle.Info mInfo;

    private List<String> paiLiangList = new ArrayList<>();
    private List<GetApiCarCc.CarCcEntity> carCcList = new ArrayList<>();


    private GetApiCarCc getApiCarCc = new GetApiCarCc(new AsyCallBack<GetApiCarCc.CarCcEntityList>() {

        @Override
        public void onSuccess(String toast, int type, GetApiCarCc.CarCcEntityList carCcEntityList) throws Exception {

            carCcList = carCcEntityList.listsCarCc;

            for (int i = 0; i < carCcList.size(); i++) {

                paiLiangList.add(carCcList.get(i).title);

            }

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);

        }

    });

    private PostVehicleCard postVehicleCard = new PostVehicleCard(new AsyCallBack<PostVehicleCard.VehicleCardEntity>() {

        @Override
        public void onSuccess(String toast, int type, PostVehicleCard.VehicleCardEntity vehicleCardEntity) throws Exception {

            if (!TextUtils.isEmpty(vehicleCardEntity.plateno) && !TextUtils.isEmpty(vehicleCardEntity.vehicletype) && !TextUtils.isEmpty(vehicleCardEntity.usecharacter) && !TextUtils.isEmpty(vehicleCardEntity.engineno) && !TextUtils.isEmpty(vehicleCardEntity.vin) && !TextUtils.isEmpty(vehicleCardEntity.model) && !TextUtils.isEmpty(vehicleCardEntity.registerdate) && !TextUtils.isEmpty(vehicleCardEntity.usecharacter)) {

                palteNum.setText(vehicleCardEntity.plateno);
                carType.setText(vehicleCardEntity.vehicletype);//这个要判断 传数字还是汉字
                useNature.setText(vehicleCardEntity.usecharacter);
                engineNum.setText(vehicleCardEntity.engineno);
                vin.setText(vehicleCardEntity.vin);
                modelNum.setText(vehicleCardEntity.model);
                recorDate.setText(vehicleCardEntity.registerdate);


                dirverCard_show_iv.setVisibility(View.VISIBLE);
                dirverCard_show_iv.setImageBitmap(PictureUtil.getSmallBitmap(declareMap.get(2)));
                ((Button) findViewById(R.id.driveCard_submit)).setText("已选择");

            } else {

                MyToast.showToast("行驶证识别失败", context);

                declareMap.put(2, null);
                dirverCard_show_iv.setVisibility(View.GONE);
                ((Button) findViewById(R.id.driveCard_submit)).setText("上传");
            }


        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            MyToast.showToast("行驶证识别失败", context);

            declareMap.put(2, null);
            dirverCard_show_iv.setVisibility(View.GONE);
            ((Button) findViewById(R.id.driveCard_submit)).setText("上传");

        }

    });


    private PostIDCard postIDCard = new PostIDCard(new AsyCallBack<PostIDCard.IdCardInfoEntity>() {
        @Override
        public void onSuccess(String toast, int type, PostIDCard.IdCardInfoEntity idCardInfoEntity) throws Exception {

//            String code, result, name, gender, people, byear, bmonth, bday, address, idnumber, authority, validdate, age;

            if (!TextUtils.isEmpty(idCardInfoEntity.name) && !TextUtils.isEmpty(idCardInfoEntity.idnumber) && !TextUtils.isEmpty(idCardInfoEntity.address)) {

                insured.setText(idCardInfoEntity.name);
                idCardNum.setText(idCardInfoEntity.idnumber);
                address.setText(idCardInfoEntity.address);

                idCard_show_iv.setVisibility(View.VISIBLE);
                idCard_show_iv.setImageBitmap(PictureUtil.getSmallBitmap(declareMap.get(1)));
                ((Button) findViewById(R.id.idCard_submit)).setText("已选择");
                ((Button) findViewById(R.id.idCard_submit)).setTextColor(getResources().getColor(R.color.bianji));

            } else {

                MyToast.showToast("身份证识别失败", context);

                declareMap.put(1, null);
                idCard_show_iv.setVisibility(View.GONE);
                ((Button) findViewById(R.id.idCard_submit)).setText("上传");
                ((Button) findViewById(R.id.idCard_submit)).setTextColor(getResources().getColor(R.color.text3a3a3a));
            }

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            MyToast.showToast("身份证识别失败", context);

            declareMap.put(1, null);
            idCard_show_iv.setVisibility(View.GONE);
            ((Button) findViewById(R.id.idCard_submit)).setText("上传");
            ((Button) findViewById(R.id.idCard_submit)).setTextColor(getResources().getColor(R.color.text3a3a3a));

        }
    });

    private InsureanceDutyfeeGet insureanceDutyfeeGet = new InsureanceDutyfeeGet(new AsyCallBack<List<InsureanceDutyfeeGet.DutyfeeEntity>>(){

        @Override
        public void onSuccess(String toast, int type, List<InsureanceDutyfeeGet.DutyfeeEntity> dutyfeeEntities) throws Exception {

            duty_price_die_tv.setText(dutyfeeEntities.get(0).fee);
            duty_no_price_die_tv.setText(dutyfeeEntities.get(1).fee);
            duty_price_hospital_tv.setText(dutyfeeEntities.get(2).fee);
            duty_no_price_hospital_tv.setText(dutyfeeEntities.get(3).fee);
            duty_price_assets_tv.setText(dutyfeeEntities.get(4).fee);
            duty_no_price_assets_tv.setText(dutyfeeEntities.get(5).fee);
            duty_price_percent_tv.setText(dutyfeeEntities.get(6).fee);

        }

        @Override
        public void onFail(String toast, int type) throws Exception {


        }
    });

    private EditText idCardNum;
    private EditText address;
    private EditText phoneNum;
    private EditText palteNum;
    private EditText engineNum;
    private EditText vin;
    private EditText modelNum;
    private EditText passengers;
    private EditText weight;
    private TextView displacement;
    private EditText power;
    private EditText totalWeight;
    private EditText taxpayerNum;
    private TextView recorDate;
    private LinearLayout lLayout_duty;//责任限额下面的
    @BoundView(R.id.duty_price_die_tv) private TextView duty_price_die_tv;
    @BoundView(R.id.duty_no_price_die_tv) private TextView duty_no_price_die_tv;
    @BoundView(R.id.duty_price_hospital_tv) private TextView duty_price_hospital_tv;
    @BoundView(R.id.duty_no_price_hospital_tv) private TextView duty_no_price_hospital_tv;
    @BoundView(R.id.duty_price_assets_tv) private TextView duty_price_assets_tv;
    @BoundView(R.id.duty_no_price_assets_tv) private TextView duty_no_price_assets_tv;
    @BoundView(R.id.duty_price_percent_tv) private TextView duty_price_percent_tv;
    private boolean flag;
    private ImageView img1;
    private ImageView img2;
    private EditText insured;


    private TextView chechuanshui_money_tv; //车船税的钱
    private ImageView idCard_show_iv;
    private ImageView dirverCard_show_iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shouye_jiaoqiangxian_tianxiexinxi);

        initView();
        setListener();

//        getApiShowVehicle.type = PrefrenceConfig.ONE;
//        getApiShowVehicle.execute(this);

        getApiCarCc.execute(this);

        insureanceDutyfeeGet.execute(this);

        chechuanshui_money_tv = ((TextView) findViewById(R.id.chechuanshui_money_tv));

        idCard_show_iv = (ImageView) findViewById(R.id.idCard_show_iv);
        dirverCard_show_iv = (ImageView) findViewById(R.id.dirverCard_show_iv);

        useNature.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

                if (s.toString().equals("营运")) {

                    findViewById(R.id.quality_qiangxian_rl).setVisibility(View.VISIBLE);
                    useNature.setTag("1");


                } else if (s.toString().equals("非营运")) {

                    findViewById(R.id.quality_qiangxian_rl).setVisibility(View.GONE);
                    useNature.setTag("2");

                } else {

                    MyToast.showToast("请输入正确使用性质 营运或非营运", context);
                }


            }
        });

        idCard_show_iv.setOnClickListener(this);
        dirverCard_show_iv.setOnClickListener(this);

    }


    private void setListener() {

        btnXiaYiBu.setOnClickListener(this);
        displacement.setOnClickListener(this);
//        carType.setOnClickListener(this);
//        useNature.setOnClickListener(this);
        recorDate.setOnClickListener(this);

        insured.addTextChangedListener(new MEditTextListener(context, 16, insured));
        idCardNum.addTextChangedListener(new MEditTextListener(context, 18, idCardNum));
        address.addTextChangedListener(new MEditTextListener(context, 30, address));
        phoneNum.addTextChangedListener(new MEditTextListener(context, 11, phoneNum));
        palteNum.addTextChangedListener(new MEditTextListener(context, 10, palteNum));
        engineNum.addTextChangedListener(new MEditTextListener(context, 20, engineNum));
        vin.addTextChangedListener(new MEditTextListener(context, 20, vin));
        modelNum.addTextChangedListener(new MEditTextListener(context, 20, modelNum));
        passengers.addTextChangedListener(new MEditTextListener(context, 2, passengers));
        weight.addTextChangedListener(new MEditTextListener(context, 10, weight));
        power.addTextChangedListener(new MEditTextListener(context, 6, power));
        totalWeight.addTextChangedListener(new MEditTextListener(context, 10, totalWeight));
        taxpayerNum.addTextChangedListener(new MEditTextListener(context, 18, taxpayerNum));

//        displacement.addTextChangedListener(new MEditTextListener(context, 5, displacement));

//        displacement.addTextChangedListener(new TextWatcher() {
//
//            private CharSequence temp = "";
//
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//                temp = s;
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//
//
//                if (temp.length() > 0) {
//
//
//                    float pailiang = Float.parseFloat(temp.toString());
//
//                    if (pailiang > 0 && pailiang <= 1.0) {
//
//                        chechuanshui_money_tv.setText("240元");
//
//                    } else if (pailiang > 1 && pailiang <= 1.6) {
//
//                        chechuanshui_money_tv.setText("420元");
//
//                    } else if (pailiang > 1.6 && pailiang <= 2) {
//
//                        chechuanshui_money_tv.setText("480元");
//
//                    } else if (pailiang > 2 && pailiang <= 2.5) {
//
//                        chechuanshui_money_tv.setText("900元");
//
//                    } else if (pailiang > 2.5 && pailiang <= 3) {
//
//                        chechuanshui_money_tv.setText("1800元");
//
//                    } else if (pailiang > 3 && pailiang <= 4) {
//
//                        chechuanshui_money_tv.setText("1800元");
//
//                    } else if (pailiang > 4) {
//
//                        chechuanshui_money_tv.setText("4500元");
//
//                    }
//
//                } else {
//
//                    chechuanshui_money_tv.setText("0元");
//
//                }
//
//
//            }
//        });


    }

    private void initView() {
        declareMap = new HashMap<>();

        findViewById(R.id.back).setOnClickListener(this);
        btnXiaYiBu = ((Button) findViewById(R.id.shouye_jiaoqinagxian_tianxiexinxi_xiayibu));
        findViewById(R.id.idCard_submit).setOnClickListener(this);
        findViewById(R.id.driveCard_submit).setOnClickListener(this);

        carType = ((EditText) findViewById(R.id.vehicleType_qiangxian));
        useNature = ((EditText) findViewById(R.id.useNature_qiangxian));

        //
        insured = ((EditText) findViewById(R.id.insured));
        idCardNum = ((EditText) findViewById(R.id.idCardNum));
        address = ((EditText) findViewById(R.id.address_qiangxian));
        phoneNum = ((EditText) findViewById(R.id.phoneNum_qiangxian));
        palteNum = ((EditText) findViewById(R.id.plateNumber_qiangxian));
        engineNum = ((EditText) findViewById(R.id.engineNum_qiangxian));
        vin = ((EditText) findViewById(R.id.VIN));
        modelNum = ((EditText) findViewById(R.id.factory_plate_model_qiangxian));
        passengers = ((EditText) findViewById(R.id.passengers));
        weight = ((EditText) findViewById(R.id.quality_qiangxian));
        displacement = ((TextView) findViewById(R.id.displacement));
        power = ((EditText) findViewById(R.id.power));
        totalWeight = ((EditText) findViewById(R.id.totalWeight_qiangxian));
        taxpayerNum = ((EditText) findViewById(R.id.taxpayerNum_qiangxian));
        recorDate = ((TextView) findViewById(R.id.recorDate_qiangxian));
        //下面是责任限额的东西   布局隐藏显示
        lLayout_duty = ((LinearLayout) findViewById(R.id.rlayout_duty));

        findViewById(R.id.duty).setOnClickListener(this);
        img1 = ((ImageView) findViewById(R.id.img1));
        img2 = ((ImageView) findViewById(R.id.img2));
        flag = true;//默认是显示
    }

    @Override
    public void onClick(View view) {

        Intent intent = null;
        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.displacement:

                showPop(view);

                return;

            case R.id.idCard_show_iv:

                new ShowPicDialog(context, declareMap.get(1)).show();

                return;

            case R.id.dirverCard_show_iv:

                new ShowPicDialog(context, declareMap.get(2)).show();

                return;

            case R.id.recorDate_qiangxian:
                DateTimePickDialogUtil dialogUtil = new DateTimePickDialogUtil(this, null);
                dialogUtil.dateTimePicKDialog(recorDate);
                return;

            case R.id.duty:
                if (flag) {
                    flag = false;
                    img1.setVisibility(View.GONE);
                    img2.setVisibility(View.VISIBLE);
                    lLayout_duty.setVisibility(View.GONE);
                } else {
                    flag = true;
                    img1.setVisibility(View.VISIBLE);
                    img2.setVisibility(View.GONE);
                    lLayout_duty.setVisibility(View.VISIBLE);
                }
                return;

            case R.id.idCard_submit:
                i = 1;


                new PictureDialog(context) {
                    @Override
                    protected void onCamera() {
                        startCamera(null);
                    }

                    @Override
                    protected void onAlbum() {
                        startAlbum(null);
                    }
                }.show();

                return;
            case R.id.driveCard_submit:
                i = 2;
                new PictureDialog(context) {
                    @Override
                    protected void onCamera() {
                        startCamera(null);
                    }

                    @Override
                    protected void onAlbum() {
                        startAlbum(null);
                    }
                }.show();

                return;
//            case R.id.vehicleType_qiangxian:
//                view.setTag("1");
//                showPop(view);
//                return;
//
//            case R.id.useNature_qiangxian:
//                view.setTag("2");
//                showPop(view);
//
//                return;

            case R.id.shouye_jiaoqinagxian_tianxiexinxi_xiayibu:
                intent = new Intent(this, CompulsoryInsurancePriceActivity.class);

                //验证 不能为空

                if (TextUtils.isEmpty(declareMap.get(1))) {
                    MyToast.showToast("请上传身份证件照片", context);
                    return;
                }

                if (TextUtils.isEmpty(insured.getText().toString())) {
                    MyToast.showToast("请输入被保险人", context);
                    return;
                }
                if (TextUtils.isEmpty(idCardNum.getText().toString())) {
                    MyToast.showToast("请输入被保险人身份证号码", context);
                    return;
                }
                if (!Validator.isIDCard(idCardNum.getText().toString())) {
                    MyToast.showToast("请输入正确身份证号", context);
                    return;
                }
                if (TextUtils.isEmpty(address.getText().toString().replaceAll(" ", ""))) {
                    MyToast.showToast("请输入被保险人地址", context);
                    return;
                }
                if (TextUtils.isEmpty(phoneNum.getText().toString())) {
                    MyToast.showToast("请输入被保险人联系电话", context);
                    return;
                }
                if (!Validator.isMobile(phoneNum.getText().toString())) {
                    MyToast.showToast("请输入正确联系电话", context);
                    return;
                }
                if (TextUtils.isEmpty(declareMap.get(2))) {
                    MyToast.showToast("请上传行驶证照片", context);
                    return;
                }

                if (TextUtils.isEmpty(palteNum.getText().toString())) {
                    MyToast.showToast("请输入号牌号码", context);
                    return;
                }
                if (!Validator.isCarNum(palteNum.getText().toString())) {
                    MyToast.showToast("请输入正确号牌号码", context);
                    return;
                }
                if (TextUtils.isEmpty(carType.getText().toString())) {

                    MyToast.showToast("请输入车辆类型", context);
                    return;
                }

                String useNature_str = useNature.getText().toString();

                if (TextUtils.isEmpty(useNature_str)) {

                    MyToast.showToast("请输入使用性质", context);
                    return;
                }

                if (useNature_str.equals("营运")) {

                    useNature.setTag("1");

                } else if (useNature_str.equals("非营运")) {

                    useNature.setTag("2");

                } else {

                    MyToast.showToast("请输入正确使用性质 营运或非营运", context);
                }

                if (TextUtils.isEmpty(engineNum.getText().toString())) {
                    MyToast.showToast("请输入发动机号码", context);
                    return;
                }
                if (TextUtils.isEmpty(vin.getText().toString())) {
                    MyToast.showToast("请输入车架号", context);
                    return;
                }
                if (TextUtils.isEmpty(modelNum.getText().toString())) {
                    MyToast.showToast("请输入厂牌型号", context);
                    return;
                }
                if (TextUtils.isEmpty(passengers.getText().toString())) {
                    MyToast.showToast("请输入核定载客", context);
                    return;
                }
                if (TextUtils.isEmpty(weight.getText().toString()) && useNature.getTag().toString().equals("1")) {
                    MyToast.showToast("货车必须输入核定载质量", context);
                    return;
                }
                if (TextUtils.isEmpty(displacement.getText().toString())) {
                    MyToast.showToast("请选择排量", context);
                    return;
                }
                if (TextUtils.isEmpty(power.getText().toString())) {
                    MyToast.showToast("请输入功率", context);
                    return;
                }
                if (TextUtils.isEmpty(recorDate.getText().toString())) {
                    MyToast.showToast("请输入登记日期", context);
                    return;
                }
                if (TextUtils.isEmpty(totalWeight.getText().toString())) {
                    MyToast.showToast("请输入整车质量", context);
                    return;
                }
                if (TextUtils.isEmpty(taxpayerNum.getText().toString())) {
                    MyToast.showToast("请输入纳税人识别号", context);
                    return;
                }
                

                Bundle bundle = getIntent().getExtras();

                UtilLog.e("===========================2", bundle.getString("insurance_type") + "sdfasdfsaasdfas");

                bundle.putString("insured", insured.getText().toString());
                bundle.putString("id_number", idCardNum.getText().toString());
                bundle.putString("address", address.getText().toString().replaceAll(" ", ""));
                bundle.putString("tel", phoneNum.getText().toString());
                bundle.putString("plate_number", palteNum.getText().toString());
                bundle.putString("cartype", carType.getText().toString());
                bundle.putString("usenature", useNature.getTag().toString());
                bundle.putString("engine_number", engineNum.getText().toString());
                bundle.putString("vin", vin.getText().toString());
                bundle.putString("model_number", modelNum.getText().toString());
                bundle.putString("passengers", passengers.getText().toString());
                bundle.putString("weight", weight.getText().toString());
                bundle.putString("displacement", displacement.getText().toString());
                bundle.putString("power", power.getText().toString());
                bundle.putString("vehicle_weight", totalWeight.getText().toString());
                bundle.putString("taxpayer_number", taxpayerNum.getText().toString());
                bundle.putString("regtime", recorDate.getText().toString());
                bundle.putString("id_url", declareMap.get(1));
                bundle.putString("drive_url", declareMap.get(2));

                //下页 请求保费用
                bundle.putString("cartype_str", carType.getText().toString());
                bundle.putString("usenature_str", useNature.getText().toString());

                //车船税价格  带下页去
                bundle.putString("cheChuanShui", chechuanshui_money_tv.getText().toString().replaceAll("元", ""));



                UtilLog.e("意外险", bundle.toString());

                intent.putExtras(bundle);

                break;

        }
        startActivity(intent);
    }



    private void showPop(View view) {

        View contentView = LayoutInflater.from(context).inflate(R.layout.pop_layout, null);

        ListView popList = ((ListView) contentView.findViewById(R.id.item_popList));

        ArrayAdapter adapter = new ArrayAdapter<String>(context, R.layout.support_simple_spinner_dropdown_item, paiLiangList);

        popList.setAdapter(adapter);

        final PopupWindow popupWindow = new PopupWindow(contentView, displacement.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT, true);

        popupWindow.setTouchable(true);

        popupWindow.setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return false;
            }
        });

        popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_white_bg));
        popupWindow.showAsDropDown(view);

        popList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                displacement.setText(paiLiangList.get(position));
                chechuanshui_money_tv.setText(carCcList.get(position).money + "元");

                popupWindow.dismiss();
            }
        });


    }


    public String bitmaptoString(Bitmap bitmap) {


        // 将Bitmap转换成字符串

        String string = null;

        ByteArrayOutputStream bStream = new ByteArrayOutputStream();

        bitmap.compress(Bitmap.CompressFormat.JPEG, 50, bStream);

        byte[] bytes = bStream.toByteArray();
        Base64Encoder base = new Base64Encoder();
        string = base.encode(bytes); //

        //  string = Base64.encodeToString(bytes, Base64.DEFAULT);

        return string;

    }

    @Override
    protected void resultPhotoPath(ImageView imageView, String s) {


        String str = bitmaptoString(PictureUtil.getSmallBitmap(s));

        String uid = BaseApplication.BasePreferences.readUserId();

        String time = System.currentTimeMillis() + "";

        String lock = UtilMD5.MD5Encode(UtilMD5.MD5Encode(uid + time, "UTF-8") + "zhang", "UTF-8");


        if (i == 1) {

            postIDCard.userid = uid;
            postIDCard.time = time;
            postIDCard.lock = lock;
            postIDCard.base = str;

            postIDCard.execute(this);


        } else if (i == 2) {

            postVehicleCard.userid = uid;
            postVehicleCard.time = time;
            postVehicleCard.lock = lock;
            postVehicleCard.base = str;

            postVehicleCard.execute(this);

        }

        declareMap.put(i, s);

    }

}
